<template>
    <el-row>
        <el-col :span="24">
            <el-form :model="newsSearchObj"
                class="search_prod tl"
                label-width="120px">
                <el-form-item label="订单号">
                    <el-col :span="5">
                        <el-col :span="24"
                            class="search_input_width">
                            <el-input size="small"
                                clearable
                                v-model="newsSearchObj.oid"
                                placeholder="订单号"></el-input>
                        </el-col>
                    </el-col>
                    <el-col class="tr col_label"
                        :span="3">会员账号&nbsp;&nbsp;&nbsp;</el-col>
                    <el-col :span="5">
                        <el-col :span="24"
                            class="search_input_width">
                            <el-input size="small"
                                clearable
                                v-model="newsSearchObj.username"
                                placeholder="会员账号"></el-input>
                        </el-col>
                    </el-col>
                    <el-col class="tr col_label"
                        :span="3">会员昵称&nbsp;&nbsp;&nbsp;</el-col>
                    <el-col :span="5">
                        <el-col :span="24"
                            class="search_input_width">
                            <el-input size="small"
                                clearable
                                v-model="newsSearchObj.nickname"
                                placeholder="会员昵称"></el-input>
                        </el-col>
                    </el-col>
                </el-form-item>

                <el-form-item label="请选择状态">
                    <el-col :span="5">
                        <el-col :span="24"
                            class="search_input_width">
                            <el-select v-model="newsSearchObj.status"
                                clearable
                                size="small"
                                placeholder="请选择状态">
                                <el-option v-for="item in options"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"></el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                    <el-col class="tr col_label"
                        :span="3">请选择类型&nbsp;&nbsp;&nbsp;</el-col>
                    <el-col :span="5">
                        <el-col :span="24"
                            class="search_input_width">
                            <el-select v-model="newsSearchObj.types"
                                clearable
                                size="small"
                                placeholder="请选择类型">
                                <el-option v-for="item in options2"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"></el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                    <el-col class="tr col_label"
                        :span="3">请选择等级&nbsp;&nbsp;&nbsp;</el-col>
                    <el-col :span="5">
                        <el-col :span="24"
                            class="search_input_width">
                            <el-select v-model="newsSearchObj.coin"
                                clearable
                                size="small"
                                placeholder="请选择等级">
                                <el-option v-for="item in coin"
                                    :key="item.id"
                                    :label="item.title"
                                    :value="item.id"></el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                </el-form-item>
                <el-form-item label="请选择时间">
                    <el-col :span="8"
                        style="width:260px">
                        <el-col :span="22"
                            class="search_time_width">
                            <el-date-picker style="width:100%"
                                v-model="createTime"
                                type="datetimerange"
                                size="small"
                                align="right"
                                unlink-panels
                                clearable
                                value-format="timestamp"
                                range-separator="-"
                                start-placeholder="开始时间"
                                end-placeholder="结束时间"
                                :picker-options="pickerOptions2">
                            </el-date-picker>
                        </el-col>
                    </el-col>
                </el-form-item>
                <el-form-item>
                    <el-button :loading='$store.state.isLoading'
                        size="small"
                        class="top_weiy"
                        type="primary"
                        @click="onSubmit">查询</el-button>
                    <el-button :loading='$store.state.isLoading'
                        size="small"
                        class="top_weiy"
                        type="primary"
                        @click="delSubmit">一键清除</el-button>
                </el-form-item>
            </el-form>
        </el-col>
    </el-row>
</template>
<script>
export default {
    name: "c2cBuySearch",
    data () {
        return {
            createTime: [],
            pickerOptions2: {
                disabledDate (time) {
                    return time.getTime() > Date.now();
                },
                shortcuts: [
                    {
                        text: "最近一周",
                        onClick (picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit("pick", [start, end]);
                        }
                    },
                    {
                        text: "最近一个月",
                        onClick (picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit("pick", [start, end]);
                        }
                    },
                    {
                        text: "最近三个月",
                        onClick (picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit("pick", [start, end]);
                        }
                    }
                ]
            },
            options: [
                {
                    value: "1",
                    label: "发布中"
                },
                {
                    value: "2",
                    label: "交易中"
                },
                {
                    value: "3",
                    label: "完成"
                },
                {
                    value: "4",
                    label: "取消"
                }
            ],
            options2: [
                {
                    value: "1",
                    label: "买"
                },
                {
                    value: "2",
                    label: "卖"
                }
            ],
            newsSearchObj: {
                oid: "",
                username: "",
                nickname: "",
                status: "",
                coin: "",
                created_time_begin: "",
                created_time_end: ""
            },
            createTime: [],
            optionProps: {
                value: "id",
                label: "title",
                children: "z"
            },
            data: [],
            op: [],
            coin: []
        };
    },
    methods: {
        getList () {
            this.$api.getCoin.getCoinGrade({}).then(res => {
                if (res.data.code == 200) {
                    this.coin = res.data.result;
                }
            });
        },
        delSubmit () {
            this.newsSearchObj = {
                oid: "",
                username: "",
                nickname: "",
                status: "",
                coin: "",
                created_time_begin: "",
                created_time_end: ""
            };
            this.$emit("sendSearch", this.newsSearchObj);
        },
        onSubmit () {
            this.$emit("sendSearch", this.newsSearchObj);
        }
    },
    created () {
        this.getList();
    },
    watch: {
        createTime (val) {
            if (val != null) {
                this.newsSearchObj.created_time_begin = this.$fnc.phptime(val[0]);
                this.newsSearchObj.created_time_end = this.$fnc.phptime(val[1]);
            } else {
                this.newsSearchObj.created_time_begin = "";
                this.newsSearchObj.created_time_end = "";
            }
        }
    }
};
</script>
